package com.caipiao.controller;

import com.caipiao.mapper.SUserMapper;
import com.caipiao.mapper.SUserWalletRecordMapper;
import com.caipiao.pojo.ObjectResult;
import com.caipiao.pojo.SUser;
import com.caipiao.pojo.SUserWalletRecord;
import com.caipiao.pojo.XMLBean;
import com.caipiao.service.WalletRecordService;
import com.caipiao.util.CommonUtils;
import com.caipiao.util.Page;
import com.caipiao.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/1/9.
 */
@Controller
@RequestMapping("/walletRecord")
public class WalletRecordController {

    @Autowired
    private WalletRecordService walletRecordService;
    @Autowired
    private SUserMapper sUserMapper;
    @Autowired
    private SUserWalletRecordMapper sUserWalletRecordMapper;

    /**
     * 储值
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/recharge",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult recharge(XMLBean xmlBean){
        Map<String,Object> map = new HashMap<>();
        String[] array = {"19857192809","19857190566","15669052627"};
        String[][] array2 = {{"联系客服1","客服微信1： 19857192809","http://app.shancaikj.com:8090/image/kefu.png"},
                {"联系客服2","客服微信2： 19857190566","http://app.shancaikj.com:8090/image/kefu.png"},
                {"联系客服3","客服微信3： 15669052627","http://app.shancaikj.com:8090/image/kefu.png"}};
        map.put("aliPay","15669052627");
        map.put("weixing","15669052627");
        map.put("explain","");
        map.put("kefuVx",array);
        map.put("kefu",array2);
        map.put("workingHours","工作时间为每天9:00-17:00");
        map.put("top","如有疑问，请联系以下客服");
        return ObjectResult.build("1","成功",map);
    }


    /**
     * 提现
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/withdraw",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult withdraw(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())|| StringUtil.isEmpty(xmlBean.getAmount())) {
            return ObjectResult.build("0", "参数丢失，请重试");
        }

        return walletRecordService.withdraw(xmlBean);
    }

    /**
     * 提现
     * @param xmlBean
     * @return
     */
    @RequestMapping(value = "/withdrawParam",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult withdrawParam(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }
        String userId = CommonUtils.decToken(xmlBean.getToken());
        Float accountAble = sUserMapper.selectByPrimaryKey(Integer.parseInt(userId)).getAccountAble();

        Map<String,Object> map = new HashMap<>();
        map.put("accountAble","可用积分: "+accountAble);
        map.put("lifting","积分提现以100积分起提");
        map.put("explain","    工作时间为每周一至周五9:00-17:00，工作日提现T+0到账，需要等待财务审核，按照申请时间顺序安排，一般是提交后2-3个小时到账，周末和节假日顺延至工作日。如有疑问，请联系客服咨询。");


        return ObjectResult.build("1","成功",map);
    }


    @RequestMapping(value = "/withdrawParamRecord",method = RequestMethod.POST)
    @ResponseBody
    public ObjectResult withdrawParamRecord(XMLBean xmlBean){
        if(StringUtil.isEmpty(xmlBean.getToken())) {
            return ObjectResult.build("0", "未登录");
        }
        String userId = CommonUtils.decToken(xmlBean.getToken());

        List<SUserWalletRecord> sUserWalletRecords = sUserWalletRecordMapper.selectUserId(Integer.parseInt(userId));

        Page<SUserWalletRecord> page = new Page<>();
        page.setP(xmlBean.getP()==null ? 1:xmlBean.getP());
        List<SUserWalletRecord> content = page.getPageContent(sUserWalletRecords);

        Map<String,Object> map = new HashMap<>();
        map.put("count",page.getPageTotal());
        map.put("list",content);

        return ObjectResult.build("1","成功",map);
    }



}
